﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;

namespace RMS.DB
{
    
    public static class ReportUtils
    {
        //private static string Finish = DailyEntryStatusValue.Text[DailyEntryStatus.Finished];        
        public static List<ReportModel> GetDataForMonthlyReport(int monthF, int yearF, int monthT, int yearT)
        {
            InvoicesMng invoiceManage = new InvoicesMng();
            var datas = new List<ReportModel>();
            if (yearF == yearT)
            {
                AddReportModel(monthF, monthT, yearT, datas, invoiceManage);
            }
            else if ((yearT - yearF) == 1)
            {
                AddReportModel(monthF, 12, yearF, datas, invoiceManage);
                AddReportModel(1, monthT, yearT, datas, invoiceManage);
            }
            else if ((yearT - yearF) > 1)
            {
                AddReportModel(monthF, 12, yearF, datas, invoiceManage);
                for (int i = (yearF + 1); i < yearT; i++)
                {
                    AddReportModel(1, 12, i, datas, invoiceManage);
                }
                AddReportModel(1, monthT, yearT, datas, invoiceManage);
            }
            return datas;
        }

        private static void AddReportModel(int mF, int mT, int y, List<ReportModel> datas, InvoicesMng invoiceManage)
        {
            for (int i = mF; i <= mT; i++)
            {
                var revenue = invoiceManage.CalculateRevenuePerMonth(i, y);
                datas.Add(new ReportModel()
                {
                    Criteria = i.ToString("00")+"/"+y.ToString().Substring(2),
                    RevenueGold =revenue[0], 
                    RevenueStone = revenue[1]
                });
            }
        }

        public static List<ReportModel> GetDataForYearlyReport(int fromyear, int toyear)
        {
            InvoicesMng invoiceManage = new InvoicesMng();
            var datas = new List<ReportModel>();
            for (int i = fromyear; i < toyear + 1; i++)
            {
                double yearRevenueGold = 0;
                double yearRevenueStone = 0;
                for (int j = 1; j < 13; j++)
                {
                    var revenue = invoiceManage.CalculateRevenuePerMonth(j, i);
                    yearRevenueGold += revenue[0];
                    yearRevenueStone += revenue[1];
                }

                datas.Add(new ReportModel()
                {
                    Criteria = i.ToString(),
                    RevenueGold = yearRevenueGold,
                    RevenueStone = yearRevenueStone
                });
            }
            return datas;
        }


    }
}
